<%-- 
    Document   : createAstaForm
    Created on : 3-gen-2013, 11.57.29
    Author     : Luciano
--%>


<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.User"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.Category"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.Image"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.DBManager"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.Product"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.UM"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%!
    private DBManager db;
    
    @Override
    public void init() throws UnavailableException{
            db=(DBManager)super.getServletContext().getAttribute("db_manager");
    }
%>

<%
        String mess="";
        if(session.getAttribute("error_on")!=null){
            mess="Unable to add the asta.<br/>"
                 + "You have an error on field:<br/>"
                 + (String)session.getAttribute("error_on") ;
            session.removeAttribute("error_on");
        }
        User user = (User)session.getAttribute("user");
        ArrayList<Product> listProd=db.getProductFromUser(user.getId());
        String strProduct="<select name=\""+"product"+"\">";
        for(Product p:listProd){
            strProduct=strProduct+"<option value=\""+p.getId()+"\" >"+p.getName()+" (disp. max: "+p.getQuantity()+")</option>";
        }
        strProduct=strProduct+"</select>";
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Vendi prodotto</title>
    </head>
    <body>
        <div class="content">
            <h1>Add Asta</h1>
        <p id="add_asta_error_log"><%=mess%></p>
        <h3>Insert the asta's data</h3>
                <form name="form_add_asta" method="post"
                action="<%=response.encodeURL(request.getContextPath()+"/services/addAsta")%>" >
                
                    <table>
                        <tr>
                            <td>Select the product:</td>
                            <td>
                            <%=strProduct%>
                            </td>
                        </tr>
                        <tr>
                            <td>Quantity: </td>
                            <td>
                                <input type="text" name="quantita"  
                                       value=""/>
                            </td>
                        </tr>
                        <tr>
                            <td>Deadline: </td>
                            <td>
                                <input type="text" name="durata"  
                                       value=""/>
                                seconds
                            </td>
                        </tr>
                        <tr>
                                <td>Start Price:</td>
                                <td>
                                    <input type=text 
                                    name="start_price"
                                    value=""
                                    />
                                    euro ;
                                </td>
                            </tr>
                            <tr>
                                <td>Min Price:</td>
                                <td>
                                    <input type=text name="min_price"
                                    value=""
                                    />
                                    euro ;
                                </td>
                            </tr>
                            <tr>
                                <td>Min Increment:</td>
                                <td>
                                    <input type=text 
                                    name="min_increment"
                                    value=""
                                    />
                                    euro ;
                                </td>
                            </tr>
                            <tr>
                                <td>Shipping price:</td>
                                <td>
                                    <input type=text 
                                    name="shipping_price"
                                    value=""
                                    />
                                    euro ;
                                </td>
                            </tr>
                        <tr>
                            <td>
                                <input type="button"
                                       onclick="ValidateAsta()"
                                    name="add_Asta"
                                    value="Add"  
                                 />
                            </td>
                        </tr>
                    </table>
                    <script type="text/javascript" 
                        src="<%=request.getContextPath()%>/javascript/addAsta.js">
                    </script>
                </form>
                                    
        </div>
    </body>
</html>
